{extend name="../../public/admin"}
{block name="title"}修改咨询{/block}
{block name="css"}
<link rel="stylesheet" href="__PUBLIC__/public/bian-ji-qi/themes/default/default.css" />
<script charset="utf-8" src="__PUBLIC__/public/bian-ji-qi/kindeditor-min.js"></script>
<script charset="utf-8" src="__PUBLIC__/public/bian-ji-qi/lang/zh_CN.js"></script>
<script src="__PUBLIC__/public/validform/Validform_v5.3.2_min.js"></script>
<link rel="stylesheet" href="__PUBLIC__/public/validform/style.css">
<script>

</script>
{/block}
{block name="body"}
{$Request.root}
<div id="container">
    <ul class="nav nav-tabs">
        <li class="active"><a href="javascript:;">添加咨询</a></li>
    </ul>
    <div style="height: 20px;"></div>
    <div>
        <form action="{:url('up')}" method="post" id="form0" enctype="multipart/form-data">
            <input type="hidden" name="id" value="{$data.id}">
            <div class="form-group input-group col-xs-3 select-right">
                <label class="input-group-addon">作者</label>
                <input type="text" name="author" class="form-control" datatype="s2-10" value="{$data.author}">
            </div>
            <div class="form-group input-group col-xs-3 select-right">
                <label class="input-group-addon">类型</label>
                <select name="type" class="form-control" datatype="n,*">
                    <option >请选择</option>
                    <template v-for="key in typeList">
                        <option :value="key.id" v-bind:selected = "type==key.id">{{key.name}}</option>
                    </template>
                </select>
                <label class="input-group-addon btn" @click="addType()"><i class="fa fa-plus"></i></label>
            </div>
            <div class="form-group input-group col-xs-3 select-right">
                <label class="input-group-addon">文章来源</label>
                <input type="text" name="source" class="form-control" datatype="s2-100" value="{$data.source}">
            </div>
            <div class="form-group input-group col-xs-3 select-right">
                <label class="input-group-addon">文章标题</label>
                <input type="text" name="name" class="form-control" datatype="s2-30" value="{$data.name}">
            </div>
            <div class="form-group select-error">
                <label>填写内容</label>
                <textarea name="content" style="width:800px;height:200px;" tip="必须20-3000个字符之间" datatype="select" class="form-control" form="form0">{$data.value}</textarea>
            </div>
            <p>
                您当前输入了 <span class="word_count1">0</span> 个文字。（字数统计包含HTML代码。必须<strong>20-3000</strong>个字符之间）<br />
            </p>
            <div class="form-group col-xs-6 text-center">
                <button class="btn btn-info" id="html">{:lang('立即提交')}</button>
                <a href="javascript:;" class="btn btn-success" @click="on()">关闭修改</a>
            </div>
        </form>

    </div>

</div>
{/block}
{block name="js"}

<script>
    (()=>{
        var bianji = '';/*全局变量*/
        var app = new Vue({
            el:'#container',
            data:{
                typeList:[],//咨询分类
                type:{$data.type}
            }
        });
        app.on=()=>{
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }

        //添加咨询组
        app.addType = ()=>{
            layer.prompt({title:'请输入名称',formTypt:1},function (val,i) {
                if (val.length > 1 && val.length < 21) {
                    $.post(DADMIN+'/journalism/add',{name:val},function () {
                        get_type(function (da) {
                            app.typeList = da;
                        });
                    });
                    layer.closeAll();
                }
                else{
                    layer.msg('必须2-20个字符',{icon:2});
                }
            });
        };

        //初始化数据
        get_type(function (da) {
            app.typeList = da;
        });
        //获取咨询
        function get_type(fn) {
            $.post(DJOURNALISM+'/zi_xun',function (da) {
                fn(da);
            });
        }

        //表单验证
        var form = $('form').Validform({
            tiptype:4,
            ajaxPost:true,
            datatype:{
                select:function () {
                    $('[name="content"]').val(bianji.html());
                    if(bianji.html().length > 3000 || bianji.html().length < 20){
                        return '必须20-3000个字符之间'
                    }
                    else{
                        return true;
                    }
                }
            },
            beforeSubmit:function () {
                $('[name="content"]').val(bianji.html());
                layer.load(2);
            },
            callback:function (da) {
                layer.closeAll();
                if(da == 1){
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                }
                else{
                    layer.msg('修改失败',{icon:2});
                }
            }

        });
        /*编辑器*/
        KindEditor.ready(function(K) {
            bianji = bianji = K.create('textarea[name="content"]', {
                afterChange : function() {
                    K('.word_count1').html(this.count());
                    K('.word_count2').html(this.count('text'));
                }
            });
        });

    })();
</script>
{/block}